from flask_appbuilder import IndexView, expose, has_access


class MyIndexView(IndexView):
    index_template = 'index.html'

    @expose('/')
    @has_access
    def index(self):
        # from flask_login import current_user
        # if not current_user.is_anonymous():
        #     return redirect('/running')
        self.update_redirect()
        return self.render_template(self.index_template,
                                    appbuilder=self.appbuilder)

    def is_admin(self):
        from flask_login import current_user
        for role in current_user.roles:
            if role.name == 'Admin':
                return True
        return False